<?php
class Order {
	var $sector;
	var $category;
	var $nameOfPromotion; // STRING
	var $promotionalItems; // ARRAY
	var $images; // array;
	var $deliveryCost;
	var $subTotal;
	var $totalCost;
	var $extras;
	var $error;
	
	function Order(){
			$this->promotionalItems = array();
			$this->images =  array();
	}
	function setSector($sector){
		$this->sector = $sector;
	}
	function setCategory($category){
		$this->category = $category;
	}
	function setNameOfPromotion($promo){
		$this->nameOfPromotion = $promo;
	}
	function getNameOfPromotion(){
		return $this->nameOfPromotion;
	}
	function setTotalCost($cost){
		$this->totalCost = $cost;
	}
	function setSubTotalCost($cost){
		$this->subTotal = $cost;
	}
	function getSector(){
		return $this->sector;
	}
	function getCategory(){
		return $this->category;
	}
	
function createOrder($post){

	$this->setSector($post['sector']);
	$this->images[] = ($post['image']);
	$this->setCategory($post['category']);
	$this->setNameOfPromotion($post['promoname']);
	$this->setSubTotalCost($post['subTotal']);
	$this->setTotalCost($post['total']);
	$this->nameOfPromotion = $post['nameOfPromotion'];
	unset($_POST['sector']);
	unset($_POST['category']);
	unset($_POST['promoname']);
	unset($_POST['imagename']);
	unset($_POST['subTotal']);
	unset($_POST['total']);
	
	$itemArray = array();
	$qtyArray = array();
	$priceArray = array();
	require_once("system/functions/stringFunctions.php");
	$SFUNCTIONS = new StringFunctions();
	foreach ( $post as $key => $val ) {
		 if (substr($key, 0, 3) == "qty") { $qtyArray[] = $val; $itemArray[] = $SFUNCTIONS->camelCase(substr($key, 4)); }
		 if (substr($key, 0, 5) == "price") { $priceArray[] = $val; }
	}
	
	for ($i=0; $i < count($qtyArray); $i++){
		$this->promotionalItems[$itemArray[$i]] = array($qtyArray[$i], $priceArray[$i]);
	}
	
	
	
	if ($_POST['numberOfItems']) {
		$this->extras['Number of Items'] = $_POST['numberOfItems'];
	}
	
	if ($_POST['foodItemsList']) {
		$this->extras['Food Items'] = $_POST['foodItemsList'];
	}

	if ($_POST['writeOwnWords']) {
		$this->extras['Write Own Words'] = $_POST['writeOwnWords'];
	}
	
	if ($_POST['writeDays']) {
		$this->extras['Days'] = $_POST['writeDays'];
	}
	
	if ($_POST['mealDealPrices']) {
		$this->extras['Meal Deal Price'] = $_POST['mealDealPrices'];
	}
	
	if ($_POST['addOwnPrice']) {
		$this->extras['Add Your own Price'] = $_POST['addOwnPrice'];
	}
	
	if ($_POST['writeTimes1'] && $_POST['writeTimes2']) {
		$this->extras['Write Times'] = $_POST['writeTimes1']."; ".$_POST['writeTimes2']; 
	}
	
	if ($_POST['addOffer']) {
		$this->extras['Add your Offer'] = $_POST['addOffer'];
	}
	if ($_FILES['addLogo']){
				if (ISSET($_FILES['addLogo']))
				{
				
					if (($_FILES["addLogo"]["type"] == "image/gif")
					|| ($_FILES["addLogo"]["type"] == "image/jpeg")
					|| ($_FILES["addLogo"]["type"] == "image/png" )
					&& ($_FILES["addLogo"]["size"] < 10000))
					{
						$filename = $_FILES['addLogo']['name'];
						$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
						$add = realpath(SITEBASE."/logos/".$filename);
						copy($_FILES['addLogo']['tmp_name'], $add);
						chmod("$add",0777);
					}else{
					
					$this->error = "Your logo is in the wrong format or it is too big.";
					}
				}
	}

}
	
	
	
function displayOrder($type="", $orderId=NULL){

	$html = "";
	$html .= "<div class=\"interior\">";
	$html .= "";
	$html .= "<div class=\"imageBlock\"><img src=\"images/promoimages/".$this->images[0]."\" width=\"127\" height=\"180\" /></div>";
	$html .= "<div class=\"form-container displayorder\">";
	$html .= "<table class=\"itemtable\">";
	$html .= "<tr class=\"odd header\">\n";
	$html .= "<td>\n";
	$html .= "<p>Name Of Promotion</p>";
	$html .= "</td>\n";
	$html .= "<td>\n";
	$html .= "<p class=\"titleHeader\">".$this->nameOfPromotion."</p>";
	$html .= "</td>\n";
	$html .= "</tr>";
	$html .= "</table>";
	
	
	if ($this->extras){
		$html .= "<table class=\"itemtable\">";
		foreach ($this->extras as $key => $val) {
		$html .= "<tr class=\"odd header\">\n";
		$html .= "<td>\n";
		$html .= "<p>".$key." : </p>";
		$html .= "</td>\n";
		$html .= "<td>\n";
		$html .= "<p class=\"titleHeader\">".$val."</p>";
		$html .= "</td>\n";
		$html .= "</tr>";
		}
		$html .= "</table>";
	}
	

	
	
	$html .= "<table class=\"itemtable confirm\">";
	$html .= "<tr class=\"tableHeader\"><td>Item</td><td>QTY</td><td>Total &pound;</td></tr>";
	foreach ($this->promotionalItems as $key => $val){
	
	
			$html .= "<tr class=\"odd trUnderline\">\n";
			$html .= "<td>\n";
			$html .= "<p>$key</p>";
			$html .= "</td>\n";
			$html .= "<td>\n";
			$html .= "<p><strong>".stripslashes(nl2br($val[0]))."</strong></p>";
			$html .= "</td>\n";
			$html .= "<td>\n";
			$html .= "<p><strong>".stripslashes(nl2br($val[1]))."</strong></p>";
			$html .= "</td>\n";
			$html .= "</tr>\n";	
	}
		/*$html .= "<tr class=\"odd header\">\n";
		$html .= "<td>\n";
		$html .= "<p>Sub Total</p>";
		$html .= "</td>\n";
		$html .= "<td>\n";
		$html .= "<p class=\"titleHeader\">".$this->subTotal."</p>";
		$html .= "</td>\n";
		$html .= "</tr>";
		*/
		$html .= "<tr class=\"odd header\">\n";
		$html .= "<td>\n";
		$html .= "<p>Total</p>";
		$html .= "</td>\n";
		$html .= "<td>\n";
		$html .= "<p class=\"titleHeader\">".$this->totalCost."</p>";
		$html .= "</td>\n";
		$html .= "</tr>";
		
		if ($type == "cart") {
			$html .= "<tr class=\"odd header\">\n";
			$html .= "<td>\n";
			$html .= "<p><a href=\"removefromcart.php?ct_session_id=".$_SESSION['ct_session_id']."&amp;id=".$orderId."\" >Delete</a></p>";
			$html .= "</td>\n";
			$html .= "<td>\n";
			$html .= "&nbsp;";
			$html .= "</td>\n";
			$html .= "</tr>";
	}
	
	$html .= "</table>";
	
	
	
	
	$html .= "</div>";
	$html .= "</div>";

        return $html;
	

	}
	
	
	function displayOrderForCart($type="", $orderId=NULL){
	
	
	if ( $_SESSION['realname'] == "Carl Wells" ) {
		// var_dump($this);
	}
	
	$html = "";
	
	$html .= "<a href=\"#".$this->nameOfPromotion."\" class=\"accLink\">".$this->nameOfPromotion."</a>\n";
	$html .= "<div class=\"interior\">\n";
	$html .= "<div class=\"imageBlock\"><img src=\"images/promoimages/".$this->images[0]."\" width=\"127\" height=\"180\" /></div>";
	$html .= "<div class=\"form-container displayorder\">";
	$html .= "<table class=\"itemtable\">";
	$html .= "<tr class=\"odd header\">\n";
	$html .= "<td>\n";
	$html .= "<p>Name Of Promotion</p>";
	$html .= "</td>\n";
	$html .= "<td>\n";
	$html .= "<p class=\"titleHeader\">".$this->nameOfPromotion."</p>";
	$html .= "</td>\n";
	$html .= "</tr>";
	$html .= "</table>";
	
	
	if ($this->extras){
		$html .= "<table class=\"itemtable\">";	
		foreach ($this->extras as $key => $val) {
		$html .= "<tr class=\"odd header\">\n";
		$html .= "<td>\n";
		$html .= "<p>".$key."</p>";
		$html .= "</td>\n";
		$html .= "<td>\n";
		$html .= "<p class=\"titleHeader\">".$val."</p>";
		$html .= "</td>\n";
		$html .= "</tr>";
		}
		$html .= "</table>";
	}
	

	
	
	$html .= "<table class=\"itemtable confirm\">";
	$html .= "<tr class=\"tableHeader\"><td>Item</td><td>QTY</td><td>Total &pound;</td></tr>";
	foreach ($this->promotionalItems as $key => $val){
	
	
			$html .= "<tr class=\"odd trUnderline\">\n";
			$html .= "<td>\n";
			$html .= "<p>$key</p>";
			$html .= "</td>\n";
			$html .= "<td>\n";
			$html .= "<p><strong>".stripslashes(nl2br($val[0]))."</strong></p>";
			$html .= "</td>\n";
			$html .= "<td>\n";
			$html .= "<p><strong>".stripslashes(nl2br($val[1]))."</strong></p>";
			$html .= "</td>\n";
			$html .= "</tr>\n";	
	}
	
		
		$html .= "<tr class=\"odd header\">\n";
		$html .= "<td>\n";
		$html .= "<p>Total</p>";
		$html .= "</td>\n";
		$html .= "<td>\n";
		$html .= "<p class=\"titleHeader\">".$this->totalCost."</p>";
		$html .= "</td>\n";
		$html .= "</tr>";
		
		if ($type == "cart") {
			$html .= "<tr class=\"odd header\">\n";
			$html .= "<td>\n";
			$html .= "<p><a href=\"removefromcart.php?ct_session_id=".$_SESSION['ct_session_id']."&amp;id=".$orderId."\" class=\"deletefromcart\" >Delete</a></p>";
			$html .= "</td>\n";
			$html .= "<td>\n";
			$html .= "&nbsp;";
			$html .= "</td>\n";
			$html .= "</tr>";
	}
	
	$html .= "</table>";
	
	
	
	
	$html .= "</div>";
	$html .= "</div>\n";
	return $html;

	}
	
	function displayEmail(){
	$html = "";
	
	$html .= "<table width=\"500\">";
	$html .= "<tr>\n";
	$html .= "<td colspan=\"2\" style=\"font-family:verdana,arial;font-size:12px;padding:3px;\"><strong>\n";
	$html .= "<p>Order From Aramark Toolkit</p></strong>";
	$html .= "</td>\n";
	$html .= "</tr>";
	$html .= "<tr>\n";
	$html .= "<td style=\"font-family:verdana,arial;font-size:12px;padding:3px;\">\n";
	$html .= "<p>Name Of Promotion</p>";
	$html .= "</td>\n";
	$html .= "<td style=\"font-family:verdana,arial;font-size:12px;padding:3px;\">\n";
	$html .= "<p><strong>".$this->nameOfPromotion."</strong></p>";
	$html .= "</td>\n";
	$html .= "</tr>";
	$html .= "</table>";
	$html .= "<hr/>";
	$html .= "<table>";
	foreach ($this->promotionalItems as $key => $val){
	
	//	foreach ($val as $title => $value){
		
			$html .= "<tr class=\"odd\">\n";
			$html .= "<td style=\"font-family:verdana,arial;font-size:12px;padding:3px;\">\n";
			$html .= "<p>$key</p>";
			$html .= "</td>\n";
			$html .= "<td style=\"font-family:verdana,arial;font-size:12px;padding:3px;\">\n";
			$html .= "<p><strong>".stripslashes(nl2br($val[0]))."</strong></p>";
			$html .= "</td>\n";
			$html .= "<td style=\"font-family:verdana,arial;font-size:12px;padding:3px;\">\n";
			$html .= "<p><strong>&pound;".stripslashes(nl2br($val[1]))."</strong></p>";
			$html .= "</td>\n";
			$html .= "</tr>\n";
			
	//	}
		
	
	}
		
	$html .= "</table>";
	$html .= "<img src=\"http://carambatesting.users55.donhost.co.uk/images/promoimages/".$this->images[0]."\" />";
	$html .= "<hr/>";
	$html .= "<table>";
	$html .= "<tr>\n";
	$html .= "<td colspan=\"2\" style=\"font-family:verdana,arial;font-size:12px;padding:3px;\"><strong>\n";
	$html .= "<p>Total Cost &pound: ".$this->totalCost."</p></strong>";
	$html .= "</td>\n";
	$html .= "</tr>";
	$html .= "</table>";
	
	
	
	return $html;

	}
	
	

}

?>